﻿using HardcoreGame.Common.Abstract;
using HardcoreGame.Common.Cores.Seasons;
using Microsoft.Xna.Framework.Graphics;
using Terraria.GameContent.Drawing;
using Terraria.ModLoader;
namespace HardcoreGame.Common.Systems.SeasonReplace
{
    public class TreeTopTextrue : ModSystem
    {
        public override void Load()
        {
            On_TileDrawing.GetTreeTopTexture += TreeTopTextureWinter;
            On_TileDrawing.GetTreeTopTexture += TreeTopTextureAutumn;
        }
        private Texture2D TreeTopTextureAutumn(On_TileDrawing.orig_GetTreeTopTexture orig, TileDrawing self, int treeTextureIndex, int treeTextureStyle, byte tileColor)
        {
            SeasonSystem seasonSystem = ModContent.GetInstance<SeasonSystem>();
            Season currentSeason = seasonSystem.currentSeason;
            int currentDay = seasonSystem.dayCounter;
            if (currentSeason is Autumn)
            {
                if (treeTextureIndex == 0)
                {
                    if (currentDay <= 6)
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_0").Value;
                        return texture;
                    }
                    else
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_0_1").Value;
                        return texture;
                    }
                }
                if (treeTextureIndex == 6)
                {
                    if (currentDay <= 6)
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_6").Value;
                        return texture;
                    }
                    else
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_6_1").Value;
                        return texture;
                    }
                }
                if (treeTextureIndex == 7)
                {
                    if (currentDay <= 6)
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_7").Value;
                        return texture;
                    }
                    else
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_7_1").Value;
                        return texture;
                    }
                }
                if (treeTextureIndex == 8)
                {
                    if (currentDay <= 6)
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_8").Value;
                        return texture;
                    }
                    else
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_8_1").Value;
                        return texture;
                    }
                }
                if (treeTextureIndex == 9)
                {
                    if (currentDay <= 6)
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_9").Value;
                        return texture;
                    }
                    else
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_9_1").Value;
                        return texture;
                    }
                }
                if (treeTextureIndex == 10)
                {
                    if (currentDay <= 6)
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_10").Value;
                        return texture;
                    }
                    else
                    {
                        Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Autumn/Tree_Tops_10_1").Value;
                        return texture;
                    }
                }
            }
            return orig(self, treeTextureIndex, treeTextureStyle, tileColor);
        }
        private Texture2D TreeTopTextureWinter(On_TileDrawing.orig_GetTreeTopTexture orig, TileDrawing self, int treeTextureIndex, int treeTextureStyle, byte tileColor)
        {
            SeasonSystem seasonSystem = ModContent.GetInstance<SeasonSystem>();
            Season currentSeason = seasonSystem.currentSeason;
            int currentDay = seasonSystem.dayCounter;
            if (currentSeason is Winter)
            {
                if (treeTextureIndex == 0)
                {
                    Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Winter/Tree_Tops_0").Value;
                    return texture;
                }
                if (treeTextureIndex == 6)
                {
                    Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Winter/Tree_Tops_6").Value;
                    return texture;
                }
                if (treeTextureIndex == 7)
                {
                    Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Winter/Tree_Tops_7").Value;
                    return texture;
                }
                if (treeTextureIndex == 8)
                {
                    Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Winter/Tree_Tops_8").Value;
                    return texture;
                }
                if (treeTextureIndex == 9)
                {
                    Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Winter/Tree_Tops_9").Value;
                    return texture;
                }
                if (treeTextureIndex == 10)
                {
                    Texture2D texture = ModContent.Request<Texture2D>("HardcoreGame/Assets/Textures/Trees/Winter/Tree_Tops_10").Value;
                    return texture;
                }
            }
            return orig(self, treeTextureIndex, treeTextureStyle, tileColor);
        }
        public override void Unload()
        {
            On_TileDrawing.GetTreeTopTexture -= TreeTopTextureWinter;
            On_TileDrawing.GetTreeTopTexture -= TreeTopTextureAutumn;
        }
    }
}
